﻿using System;
using System.Linq;
using System.Threading;
using System.Windows.Media;
using Styx;
using Styx.Common;
using Styx.CommonBot;
using Styx.CommonBot.Inventory;
using Styx.Helpers;
using Styx.Pathing;
using Styx.TreeSharp;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using Action = Styx.TreeSharp.Action;

namespace MIBHunter
{
    public partial class Classname
    {

        #region CheckStance

        public bool CheckStanceState;

        private Composite CheckStance()
        {
            return new PrioritySelector(
                new Decorator(
                    ret =>
                    !CheckStanceState &&
                    SpellManager.HasSpell("Aspect of the Iron Hawk") &&
                    !CastingorGCDL() &&
                    !Me.HasAura("Aspect of the Iron Hawk"),
                    new Action(delegate
                        {
                            CastSpell("Aspect of the Iron Hawk", Me, "CheckStance");
                            CheckStanceState = true;
                        })),
                new Decorator(
                    ret =>
                    !CheckStanceState &&
                    SpellManager.HasSpell("Aspect of the Hawk") &&
                    !CastingorGCDL() &&
                    !Me.HasAura("Aspect of the Hawk"),
                    new Action(delegate
                        {
                            CastSpell("Aspect of the Hawk", Me, "CheckStance");
                            CheckStanceState = true;
                        }))
                );
        }

        #endregion

        #region SerpentSting

        private Composite SerpentSting()
        {
            return new Decorator(
                ret =>
                SpellManager.HasSpell("Serpent Sting") &&
                !Me.Mounted &&
                Attackable(Me.CurrentTarget, 5) &&
                FacingOverride(Me.CurrentTarget) &&
                !CastingorGCDL() &&
                SpellManager.CanCast("Serpent Sting"),
                new Action(delegate
                    {
                        SafelyFacingTarget(Me.CurrentTarget);
                        CastSpell("Serpent Sting", Me.CurrentTarget, "Serpent Sting");
                    })
                );
        }

        #endregion

        #region StopCastingCheck

        public void StopCastingCheck()
        {
        }

        #endregion

        #region UseRacial

        private Composite UseRacial()
        {
            return new PrioritySelector(
                new Decorator(
                    ret =>
                    Me.Combat &&
                    MIBSettings.Instance.AutoRacial && DebuffCCDuration(Me, 3000) &&
                    SpellManager.HasSpell("Every Man for Himself") &&
                    !Me.HasAura("Sap") &&
                    SpellManager.CanCast("Every Man for Himself"),
                    new Action(delegate
                        {
                            if (MIBSettings.Instance.AutoTarget && Me.CurrentTarget == null &&
                                ValidUnit(MyLastTarget))
                            {
                                MyLastTarget.Target();
                            }

                            if (DebuffCCBreakonDamage(Me) &&
                                DebuffDot(Me))
                            {
                                Logging.Write(" - Warte auf Dot / Hand der Aufopferung hebt es auf!");
                            }
                            else
                            {
                                Logging.Write(" - Benutze Jeder für sich");
                                CastSpell("Every Man for Himself", Me);
                            }
                            return RunStatus.Failure;
                        })),
                //Steingestalt
                new Decorator(
                    ret =>
                    Me.Combat &&
                    MIBSettings.Instance.AutoRacial && Me.HealthPercent < MIBSettings.Instance.UrgentHeal &&
                    SpellManager.HasSpell("Stoneform") &&
                    SpellManager.CanCast("Stoneform"),
                    new Action(delegate
                        {
                            {
                                Logging.Write("Steingestalt");
                                CastSpell("Stoneform", Me);
                            }
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    Me.Combat &&
                    MIBSettings.Instance.AutoRacial && Me.HealthPercent < MIBSettings.Instance.UrgentHeal &&
                    SpellManager.HasSpell("Gift of the Naaru") &&
                    SpellManager.CanCast("Gift of the Naaru"),
                    new Action(delegate
                        {
                            {
                                Logging.Write("Gabe der Naaru");
                                CastSpell("Gift of the Naaru", Me);
                            }
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    Me.Combat &&
                    MIBSettings.Instance.AutoRacial && Me.ManaPercent < MIBSettings.Instance.PriorityHeal &&
                    SpellManager.HasSpell("Arcane Torrent") && SpellManager.HasSpell("Holy Insight") &&
                    (Me.CurrentMap.IsDungeon || Me.CurrentMap.IsRaid) &&
                    SpellManager.CanCast("Arcane Torrent"),
                    new Action(delegate
                        {
                            {
                                Logging.Write("Arkaner Sturm");
                                CastSpell("Arcane Torrent", Me);
                            }
                            return RunStatus.Failure;
                        }))
                );
        }

        #endregion

        #region UseTrinket

        private Composite UseTrinket()
        {
            return new PrioritySelector(
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket1 == 1 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Trinket1 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket1),
                    new Action(delegate
                        {
                            Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name +
                                          " auf Cooldown");
                            StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket1 == 2 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Trinket1 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket1),
                    new Action(delegate
                        {
                            Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name +
                                          " auf Cooldown (Bosskampf)");
                            StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket1 == 3 &&
                    MIBSettings.Instance.Burst &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Trinket1 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket1),
                    new Action(delegate
                        {
                            Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name +
                                          " wegen Burst Modus");
                            StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket1 == 4 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Trinket1 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket1) &&
                    DebuffCCDuration(Me, 3000) && !Me.HasAura("Sap"),
                    new Action(delegate
                        {
                            Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name +
                                          " wegen Kontrollverlust");
                            StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket1 == 5 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.HealthPercent < MIBSettings.Instance.Trinket1HP &&
                    Me.Inventory.Equipped.Trinket1 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket1),
                    new Action(delegate
                        {
                            Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name +
                                          " wegen wenig HP");
                            StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket1 == 6 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Trinket1 != null &&
                    UnitHeal != null && UnitHeal.IsValid && UnitHeal.HealthPercent < MIBSettings.Instance.Trinket1HP &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket1),
                    new Action(delegate
                        {
                            Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name +
                                          " wegen Freund wenig HP");
                            StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket1 == 7 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Trinket1 != null &&
                    Attackable(Me.CurrentTarget, 5) &&
                    !Me.CurrentTarget.IsPet &&
                    Me.CurrentTarget.HealthPercent < MIBSettings.Instance.Trinket1HP &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket1),
                    new Action(delegate
                        {
                            Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name +
                                          " wegen Gegner wenig HP");
                            StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket1 == 8 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.ManaPercent < MIBSettings.Instance.Trinket1HP &&
                    Me.Inventory.Equipped.Trinket1 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket1),
                    new Action(delegate
                        {
                            Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name +
                                          " wegen wenig Mana");
                            StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                            return RunStatus.Failure;
                        })),
                //Trinket 2
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket2 == 1 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Trinket2 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket2),
                    new Action(delegate
                        {
                            Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name +
                                          " auf Cooldown");
                            StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket2 == 2 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Trinket2 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket2),
                    new Action(delegate
                        {
                            Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name +
                                          " auf Cooldown (Bosskampf)");
                            StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket2 == 3 &&
                    MIBSettings.Instance.Burst &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Trinket2 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket2),
                    new Action(delegate
                        {
                            Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name +
                                          " wegen Burst Modus");
                            StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket2 == 4 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Trinket2 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket2) &&
                    DebuffCCDuration(Me, 3000) && !Me.HasAura("Sap"),
                    new Action(delegate
                        {
                            Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name +
                                          " wegen Kontrollverlust");
                            StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket2 == 5 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.HealthPercent < MIBSettings.Instance.Trinket2HP &&
                    Me.Inventory.Equipped.Trinket2 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket2),
                    new Action(delegate
                        {
                            Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name +
                                          " wegen wenig HP");
                            StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket2 == 6 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Trinket2 != null &&
                    UnitHeal != null && UnitHeal.IsValid && UnitHeal.HealthPercent < MIBSettings.Instance.Trinket2HP &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket2),
                    new Action(delegate
                        {
                            Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name +
                                          " wegen Freund wenig HP");
                            StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket2 == 7 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Trinket2 != null &&
                    Attackable(Me.CurrentTarget, 5) &&
                    !Me.CurrentTarget.IsPet &&
                    Me.CurrentTarget.HealthPercent < MIBSettings.Instance.Trinket2HP &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket2),
                    new Action(delegate
                        {
                            Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name +
                                          " wegen Gegner wenig HP");
                            StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket2 == 8 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.ManaPercent < MIBSettings.Instance.Trinket2HP &&
                    Me.Inventory.Equipped.Trinket2 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket2),
                    new Action(delegate
                        {
                            Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name +
                                          " wegen wenig Mana");
                            StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                            return RunStatus.Failure;
                        }))
                );
        }

        #endregion

        #region UseProfession

        private Composite UseProfession()
        {
            return new PrioritySelector(
                //Engineering
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 1 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Hands != null &&
                    Attackable(Me.CurrentTarget, 30) &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Hands),
                    new Action(delegate
                        {
                            Logging.Write("Benutze Handschuhe Buff, aktiviert auf Cooldown");
                            StyxWoW.Me.Inventory.Equipped.Hands.Use();
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 2 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Attackable(Me.CurrentTarget, 30) &&
                    Me.CurrentTarget.IsBoss &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Hands),
                    new Action(delegate
                        {
                            Logging.Write("Benutze Handschuhe Buff, aktiviert auf Cooldown (Bosskampf)");
                            StyxWoW.Me.Inventory.Equipped.Hands.Use();
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 3 &&
                    MIBSettings.Instance.Burst &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Hands != null &&
                    Attackable(Me.CurrentTarget, 30) &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Hands),
                    new Action(delegate
                        {
                            Logging.Write("Benutze Handschuhe Buff, aktiviert Burst Modus");
                            StyxWoW.Me.Inventory.Equipped.Hands.Use();
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 4 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Hands != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Hands) &&
                    DebuffCCDuration(Me, 3000),
                    new Action(delegate
                        {
                            Logging.Write("Benutze Handschuhe Buff, aktiviert Kontrollverlust");
                            StyxWoW.Me.Inventory.Equipped.Hands.Use();
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 5 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Hands != null &&
                    Me.HealthPercent < MIBSettings.Instance.ProfBuffHP &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Hands),
                    new Action(delegate
                        {
                            Logging.Write("Benutze Handschuhe Buff, aktiviert wenig HP");
                            StyxWoW.Me.Inventory.Equipped.Hands.Use();
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 6 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Hands != null &&
                    UnitHeal != null && UnitHeal.IsValid && UnitHeal.IsAlive &&
                    UnitHeal.HealthPercent < MIBSettings.Instance.ProfBuffHP &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Hands),
                    new Action(delegate
                        {
                            Logging.Write("Benutze Handschuhe Buff, aktiviert Freund wenig HP");
                            StyxWoW.Me.Inventory.Equipped.Hands.Use();
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 7 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Hands != null &&
                    Attackable(Me.CurrentTarget, 5) &&
                    !Me.CurrentTarget.IsPet &&
                    Me.CurrentTarget.HealthPercent < MIBSettings.Instance.ProfBuffHP &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Hands),
                    new Action(delegate
                        {
                            Logging.Write("Benutze Handschuhe Buff, aktiviert Gegner wenig HP");
                            StyxWoW.Me.Inventory.Equipped.Hands.Use();
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 8 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Hands != null &&
                    Me.ManaPercent < MIBSettings.Instance.ProfBuffHP &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Hands),
                    new Action(delegate
                        {
                            Logging.Write("Benutze Handschuhe Buff, aktiviert wenig Mana");
                            StyxWoW.Me.Inventory.Equipped.Hands.Use();

                            return RunStatus.Failure;
                        })),
                //Kräuterkunde
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 1 &&
                    SpellManager.HasSpell("Lifeblood") &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Attackable(Me.CurrentTarget, 5) &&
                    SpellManager.CanCast("Lifeblood"),
                    new Action(delegate
                        {
                            Logging.Write("Benutze Lebensblut, aktiviert auf Cooldown");
                            CastSpell("Lifeblood", Me);
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 2 &&
                    SpellManager.HasSpell("Lifeblood") &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Attackable(Me.CurrentTarget, 50) &&
                    Me.CurrentTarget.IsBoss &&
                    SpellManager.CanCast("Lifeblood"),
                    new Action(delegate
                        {
                            Logging.Write("Benutze Lebensblut, aktiviert auf Cooldown (Bosskampf)");
                            CastSpell("Lifeblood", Me);
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 3 &&
                    MIBSettings.Instance.Burst &&
                    SpellManager.HasSpell("Lifeblood") &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    SpellManager.CanCast("Lifeblood"),
                    new Action(delegate
                        {
                            Logging.Write("Benutze Lebensblut, aktiviert Burst Modus");
                            CastSpell("Lifeblood", Me);
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 4 &&
                    SpellManager.HasSpell("Lifeblood") &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    DebuffCCDuration(Me, 3000) &&
                    SpellManager.CanCast("Lifeblood"),
                    new Action(delegate
                        {
                            Logging.Write("Benutze Lebensblut, aktiviert Kontrollverlust");
                            CastSpell("Lifeblood", Me);
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 5 &&
                    SpellManager.HasSpell("Lifeblood") &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.HealthPercent < MIBSettings.Instance.ProfBuffHP &&
                    SpellManager.CanCast("Lifeblood"),
                    new Action(delegate
                        {
                            Logging.Write("Benutze Lebensblut, aktiviert wenig HP");
                            CastSpell("Lifeblood", Me);
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 6 &&
                    SpellManager.HasSpell("Lifeblood") &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    UnitHeal != null && UnitHeal.IsValid && UnitHeal.IsAlive &&
                    UnitHeal.HealthPercent < MIBSettings.Instance.ProfBuffHP &&
                    SpellManager.CanCast("Lifeblood"),
                    new Action(delegate
                        {
                            Logging.Write("Benutze Lebensblut, aktiviert Freund wenig HP");
                            CastSpell("Lifeblood", Me);
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 7 &&
                    SpellManager.HasSpell("Lifeblood") &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Attackable(Me.CurrentTarget, 5) &&
                    !Me.CurrentTarget.IsPet &&
                    Me.CurrentTarget.HealthPercent < MIBSettings.Instance.ProfBuffHP &&
                    SpellManager.CanCast("Lifeblood"),
                    new Action(delegate
                        {
                            Logging.Write("Benutze Lebensblut, aktiviert Gegner wenig HP");
                            CastSpell("Lifeblood", Me);
                            return RunStatus.Failure;
                        })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 8 &&
                    SpellManager.HasSpell("Lifeblood") &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.ManaPercent < MIBSettings.Instance.ProfBuffHP &&
                    SpellManager.CanCast("Lifeblood"),
                    new Action(delegate
                        {
                            Logging.Write("Benutze Lebensblut, aktiviert wenig Mana");
                            CastSpell("Lifeblood", Me);
                            return RunStatus.Failure;
                        }))
                )
                ;
        }

        #endregion

    }
}